//
//  CZEmoticonPageView.swift
//  CZVVeiBo
//
//  Created by smile on 2017/8/6.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class CZEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        let flowLayout = UICollectionViewFlowLayout()
        flowLayout.itemSize = CGSize(width: CZSCREENW, height: 216 - 35)
        // 间距
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0
        // 滚动方向
        flowLayout.scrollDirection = .horizontal
        super.init(frame: frame, collectionViewLayout: flowLayout)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = UIColor(patternImage: UIImage(named:"emoticon_keyboard_background")!)
        dataSource = self
        register(CZCZEmoticonPageViewCell.self, forCellWithReuseIdentifier: "cell")
    }

}

extension CZEmoticonPageView: UICollectionViewDataSource{

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return CZEmoticonTools.share.allEmoticons.count
        
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return CZEmoticonTools.share.allEmoticons[section].count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as!CZCZEmoticonPageViewCell
        cell.indexPath = indexPath
        // 赋值
        cell.emoticons = CZEmoticonTools.share.allEmoticons[indexPath.section][indexPath.item]
        return cell
    }
}

